package com.xing.Intercept;

import java.io.Serializable;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class LoginInterceptor  extends AbstractInterceptor implements Serializable  {
		private static final long serialVersionUID = -1607979833695817962L;
		@Override
		public String intercept(ActionInvocation invocation) throws Exception {
			    HttpServletRequest request = ServletActionContext.getRequest();
			    ActionContext ac=invocation.getInvocationContext();
				String tmpStr = request.getRequestURI().substring(request.getRequestURI().indexOf("/") + 1);
				String uri = tmpStr;		
				if (uri.contains("login_login.action") ) {
					return invocation.invoke();
				}else{
					HttpSession session=request.getSession();
					if(session.getAttribute("user")==null) {
						return "nologin";
					}
					return invocation.invoke();
				}
	}

}
